package com.tust.app.service.impl;

import com.tust.app.dao.TopicMapper;
import com.tust.app.domain.Topic;
import com.tust.app.service.TopicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class TopicServiceImpl implements TopicService {

    @Autowired
    private TopicMapper topicMapper;

    @Override
    public List<Topic> topicList() {
        return topicMapper.selectAllTopic();
    }

    @Override
    public List<Topic> findAll() {
        return topicMapper.selectAllTopic();
    }

    @Override
    public Topic findById(Integer id) {
        return topicMapper.selectTopicById(id);
    }

    @Override
    public void insert(Topic topic) {
        topicMapper.writeTopic(topic);
    }

    @Override
    public boolean modifyTopic(Topic topic) {
        return topicMapper.updateTopicById(topic);
    }


    @Override
    public List<Topic> search(String title) {
        if (title != null && title.length() > 0) {
            return topicMapper.selectTopicByTitle(title);
        } else {
            return Collections.emptyList();
        }
    }

    @Override
    public Topic findTopicById(Integer id) {
        return topicMapper.selectTopicById(id);
    }

    @Override
    public boolean delTopic(Integer id) {
        return topicMapper.deleteTopicById(id);
    }
}